package com.gxa.customer.controller;

import com.gxa.common.commons.R;
import com.gxa.customer.redis.AccessLimit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;


@RestController
@RequestMapping("/customer")
public class CustomerTest {
    @Autowired
    private RedisTemplate redisTemplate;

    @Value("${server.port}")
    private String serverPort;
    @AccessLimit(seconds = 1, maxCount = 3, apiName = "approvalRejected", timeUnit = TimeUnit.MINUTES)
    @GetMapping("/test")
    public R customerTest(Integer id) {

        R r = new R();
        r.setCode(200);
        r.setMsg(id+"");
        r.setData(serverPort);
        return r;
    }
    @AccessLimit(seconds = 1, maxCount = 3, apiName = "approvalRejected", timeUnit = TimeUnit.MINUTES)
    @GetMapping("/test2")
    @PreAuthorize("hasAnyAuthority('system:menu:add')")
    public R customerTest2(Integer id) {

        R r = new R();
        r.setCode(200);
        r.setMsg(id+"");
        r.setData(serverPort);
        return r;
    }
    @AccessLimit(seconds = 1, maxCount = 3, apiName = "approvalRejected", timeUnit = TimeUnit.MINUTES)
    @GetMapping("/test3")
    public R customerTest3(Integer id) {

        R r = new R();
        r.setCode(200);
        r.setMsg(id+"");
        r.setData(serverPort);
        return r;
    }
}